<?php


/*
 * Created on 2009-9-12
 * Author guobin@yizin.net
 */
 
 
class InterceptorChain
{
    private $interceptors;

    private $end;

    private $current;

    public function __construct($interceptors, $end)
    {
        $this->interceptors = $interceptors;
        $this->end = $end;
        $this->current = 0;
    }

    public function next( & $context)
    {
        if ($this->current == count($this->interceptors))
        {
            $end = $this->end;
            $end($context);
            return;
        }
        $previous = $this->current;
        $this->current++;
        $this->interceptors[$previous]->intercept($context, $this);

    }
}

abstract class Interceptor
{
    public $matches;
    public abstract function intercept( & $context, InterceptorChain $chain);
}

?>